from playwright.sync_api import Page


class Dialog:
    def __init__(self, page: Page):
        self.page = page

    @staticmethod
    def dismiss_handle_dialog(dialog):
        """关闭对话框 handle"""
        dialog.dismiss()

    @staticmethod
    def accept_handle_dialog(dialog):
        """接受对话框 handle"""
        dialog.accept()

    def dialog_accept(self):
        """接受对话框"""
        self.page.on("dialog", self.accept_handle_dialog)

    def dialog_dismiss(self):
        """关闭对话框"""
        self.page.on("dialog", self.dismiss_handle_dialog)
